package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.common.Result;
import com.amsp.oa.oademo.entity.EmployeeReinstatement;
import com.amsp.oa.oademo.service.EmployeeReinstatementService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/employee-reinstatement")
@Api(tags = "员工复职申请接口")
public class EmployeeReinstatementController {

    @Autowired
    private EmployeeReinstatementService employeeReinstatementService;

    @PostMapping("/save")
    @ApiOperation("保存复职申请")
    public Result<Boolean> save(@RequestBody EmployeeReinstatement employeeReinstatement) {
        return Result.ok(employeeReinstatementService.saveOrUpdate(employeeReinstatement));
    }

    @PostMapping("/batch-save")
    @ApiOperation("批量保存复职申请")
    public Result<Boolean> batchSave(@RequestBody List<EmployeeReinstatement> records) {
        return Result.ok(employeeReinstatementService.saveOrUpdateBatch(records));
    }

    @GetMapping("/list")
    @ApiOperation("获取复职申请列表")
    public Result<IPage<EmployeeReinstatement>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String employeeName,
            @RequestParam(required = false) String employeeId,
            @RequestParam(required = false) String originalDepartment) {
        return Result.ok(employeeReinstatementService.getPage(current, size, employeeName, employeeId, originalDepartment));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取复职申请详情")
    public Result<EmployeeReinstatement> getById(@PathVariable Long id) {
        return Result.ok(employeeReinstatementService.getById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除复职申请")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(employeeReinstatementService.removeById(id));
    }
} 